package com.sifang.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sifang.dao.DriverDao;
import com.sifang.domain.Driver;
import com.sifang.domain.PageBean;
import com.sifang.service.IDriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DriverServiceImpl implements IDriverService {

    @Autowired
    private DriverDao driverDao;

    //驾驶员详情
    @Override
    public Driver detail(Integer id) {
        Driver d = driverDao.detail(id);
        return d;
    }

    //驾驶员分页显示
    @Override
    public PageBean<Driver> list(Integer pageNum, Integer pageSize) {
        //创建PageBean对象
        PageBean<Driver> pd = new PageBean<>();
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);

        List<Driver> ds = driverDao.list();
        Page<Driver> d = (Page<Driver>) ds;
        pd.setTotal(d.getTotal());
        pd.setItems(d.getResult());
        return pd;
    }
}
